<template>
  <div>
    <h4 :style="{ marginBottom: '20px' }" v-if="title">{{ title }}</h4>
    <v-chart v-if="dataSource.length>3" key="2" :forceFit="true" :height="height" :data="dataSource" :scale="scale" :padding="padding">
      <v-tooltip/>
      <v-axis/>
      <v-bar :position="position"  />
    </v-chart>
    <v-chart v-else key="1" :forceFit="true" :height="height" :data="dataSource" :scale="scale" :padding="padding">
      <v-tooltip/>
      <v-axis/>
      <v-bar :position="position" :size="40" />
    </v-chart>
  </div>
</template>

<script>
import { triggerWindowResizeEvent } from '@/utils/util'
export default {
  name: 'Bar',
  props: {
    dataSource: {
      type: Array,
      required: true
    },
    yaxisText: {
      type: String,
      default: 'y'
    },
    yaxisField: {
      type: String,
      default: 'y'
      // required:true
    },
    color: {
      type: String,
      default: 'x'
    },
    title: {
      type: String,
      default: ''
    },
    height: {
      type: Number,
      default: 254
    }
  },
  data() {
    return {
      padding: ['auto', 'auto', '40', '50'],
      position: this.color + '*' + this.yaxisField
    }
  },
  computed: {
    scale() {
      return [{
        dataKey: this.yaxisField
        // alias: this.yaxisText
      }]
    }
  },
  mounted() {
    // triggerWindowResizeEvent()
  }
}
</script>
